//global
var amallGlobal = function() {

    var handlePickers = function() {

        if (!$().datepicker) {
            return;
        }

        $('.date-picker').each(function() {

            if (!!$(this).data('cpsb')) {

            } else {
                $(this).data('dateEndDate', '0d');
            }

            var dateOptions = $.extend({
                    autoclose: true,
                    format: 'yyyy-mm-dd',
                    weekStart: 1,
                    todayBtn: 'linked',
                    language: 'cn'
                },
                $(this).data());

            var datepicker = $(this);

            $().datepicker && $(this).datepicker(dateOptions).on('changeDate', function(d) {
                var date = d.date;
                var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
                var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
                var iName = $('input:first', $(this)).prop('name');

                nextDateOptions = $.extend(dateOptions, {
                    "dateEndDate": lastDay
                });

                $(this).next('.date-picker').datepicker('setEndDate', lastDay);
                $(this).next('.date-picker').datepicker('setStartDate', date);
                $(this).prev('.date-picker').datepicker('setStartDate', firstDay);
                $(this).prev('.date-picker').datepicker('setEndDate', date);

            });

            $('i.fa-remove', this).parent().on('click', function(e) {
                e.preventDefault();
                $('input', $(datepicker)).val('');
                $(datepicker).datepicker('hide');
            });
        });

        $('.datetime-picker').each(function() {
            //console.log($(this));
            $(this).datetimepicker({
                format: 'YYYY-MM-DD hh:mm',
                // defaultDate: new Date(),
                // minDate: new Date(),
                allowInputToggle: true,
                // useStrict: true,
                autoclose: true,
                sideBySide: true,
                language: 'cn'
            });
        });

        $('.timepicker').each(function(){
        	$(this).timepicker({
               // template:'modal',
                template:false,
        		minuteStep: 10,
        		showSeconds: false,
                showInputs:false,
                // disableFocus :false,
        		showMeridian: false
        	});
        });
    }


    var handleTextarea = function() {
        // $('.text-editor').each(function(){

        // });
    }

    return {
        init: function() {
            handlePickers();
        },
        handleTextarea: function() {
            handleTextarea();
        }
    };
}();